'use strict';

if (zxcv && !zxcv.raw.PlainText) {
    zxcv.raw.PlainText = function (uri, onload, onerror) {
        var self = this,
            xhr = new XMLHttpRequest();
            
        this.content = '';
        this.status = zxcv.ASSET_LOADING;
        xhr.open('GET', uri, true);
        xhr.onreadystatechange = function () {
            if (xhr.readyState !== 4)
                return;
                
            if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
                self.content = xhr.responseText;
                self.status = zxcv.ASSET_LOADED;
                if (onload)
                    onload.call(self);
            }
            else {
                self.status = zxcv.ASSET_NOT_FOUND;
                if (onerror)
                    onerror.call(self);
            }
        };
        xhr.send(null);
    }
}